import { useMemo, useRef, useState } from "react";

export default function Demo9()
{
    const [name, SetName] = useState('张三');
    const [age, SetAge] = useState(18);
    const InputRef = useRef(null);

    const NewName = useMemo(() =>
    {
        console.log(InputRef.current);
        return `my name is ${name},随机数为${Math.random()}`
    },[name]);

    return (
        <>
            <h3>useMemo的用</h3>
            姓名：
            <input
                type="text"
                value={name}
                onChange={(e) => SetName(e.target.value)}
                ref={InputRef}
            />
            年龄：
            <input
                type="text"
                value={age}
                onChange={(e) => SetAge(e.target.value * 1)}
            />
            <br />
            {/* my name is {name},随机数为{Math.random()} */}

            {NewName}
        </>
    )
}